﻿/**
 * 注册表单验证
 */

function ckpwd() {
	
	var pwd = document.getElementById("pwd").value;
	
	var pwd1 = /^[a-zA-Z]\w{5,17}$/;
	
	if (!pwd1.test(pwd)) {
		document.getElementById("sppwd").innerHTML = "长度6-18位之间，包含字母，数字，下划线的组合";		
		return false;
	}
	if (pwd1.test(pwd)) {
		document.getElementById("sppwd").innerHTML = "√";	
		
	}
	
	return true;
}

function ckrname() {
	var rname = document.getElementById("rname").value;
	// document.getElementById("sprname").style.color = "red";
	var name1 = /^[\u4e00-\u9fa5]{2,4}$/;
	// 正则表达式验证姓名
	if (!name1.test(rname)) {
		document.getElementById("sprname").innerHTML = "姓名必须为汉字，长度2-4位";
		return false;
	}
	if (name1.test(rname)) {
		document.getElementById("sprname").innerHTML = "√";	
		
	}
	return true;
}

function ckuid() {
	var uid = document.getElementById("uid").value;
	

	var reg=/^[1-9][0-9]{5}(19[0-9]{2}|200[0-9]|2016)(0[1-9]|1[0-2])(0[1-9]|[12][0-9]|3[01])[0-9]{3}[0-9xX]$/;
	
	
	if (!reg.test(uid)) {
		document.getElementById("spuid").innerHTML = "身份证格式不正确";
		return false;
	} else {
		var index = parseInt(uid.charAt(16));
		if (index % 2 == 0) {
			document.getElementById("woman").checked = true;
		} else {
			document.getElementById("man").checked = true;
		}
		

	}
	if (reg.test(uid)) {
		document.getElementById("spuid").innerHTML = "√";	
		
	}
	return true;
}
function ckphone() {

	var phone = document.getElementById("phone").value;
	var reg = /^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|17[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/;

	if (!reg.test(phone)) {
		document.getElementById("spphone").innerHTML = "请正确输入手机号";
		return false;
	}
	if (reg.test(phone)) {
		document.getElementById("spphone").innerHTML = "√";
		
	}
	 return true;
}

function ckaddress() {
	var address = document.getElementById("address").value;
	
	var str = document.getElementById('address').value.trim();
	if (str.length == 0) {
		document.getElementById("spaddress").innerHTML = "地址栏不能为空";
		return false;
	}
	if (str.length != 0) {
		document.getElementById("spaddress").innerHTML = "√";
		
	}
	return true;
}

function ckemail() {
	var email = document.getElementById("email").value;
	
	reg = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
	if (!reg.test(email)) {
		document.getElementById("spemail").innerHTML = "电子邮箱不能是空,必须包含@,.且必须在@之后";
		return false;
	}
	if (reg.test(email)) {
		document.getElementById("spemail").innerHTML = "√";
		
	}
	return true;
}

function ckall() {
	var flag = ckuname() && ckpwd() && ckrname() && ckuid() && ckphone()
			&& ckaddress() && ckemail();
	if (flag == false) {
		alert("内容填写不完整");
		return flag;
	}
}

/**
 * 登录表单验证
 */
function ckloginuname() {
	var uname1 = document.getElementById("uname").value;
	// document.getElementById("spuname").style.color="red";
	var reg = /^[a-zA-Z]\w{5,9}$/;
	if (!reg.test(uname1)) {
		document.getElementById("spuname").innerHTML = "长度不能小于6位的字母";
		return false;
	}
	if (reg.test(uname1)) {
		document.getElementById("spuname").innerHTML = "√";
		
	}
	return true;
}

function ckloginpwd() {
	var pwd2 = document.getElementById("pwd").value;
	
	var pwd1 = /^[a-zA-Z]\w{5,17}$/;
	
	if (!pwd1.test(pwd2)) {
		document.getElementById("sppwd").innerHTML = "长度6-18位之间，包含字母，数字，下划线的组合";
		return false;
	}
	if (pwd1.test(pwd2)) {
		document.getElementById("sppwd").innerHTML = "√";
		
	}
	return true;
}

function ckyan() {
	var yan = document.getElementById("yan").value;
	
	if (yan == null || yan == "") {		
		document.getElementById("spyan").innerHTML = "请输入验证码";
		return false;
	}
	if (yan != null || yan != "") {		
		document.getElementById("spyan").innerHTML = "√";
		
	}

return true;
	
}






function ckloginall() {
	var flag= ckloginuname()&&ckloginpwd() &&ckyan();
	if (flag == false) {
	alert("请输入完整的内容");
}
return flag;
	
	
}

function huan() {
	document.getElementById("yanzheng").src = ".../../ImgServlet?date="+ new Date().getTime();
}



///**
// * 更改密码验证
// */
//function ckoldpwd() {
//	var pwd = document.getElementById("oldpwd").value;
//	
//	var pwd1 = /^[a-zA-Z]\w{5,17}$/;
//	// 正则表达式验证密码
//	if (!pwd1.test(pwd)) {
//		document.getElementById("spoldpwd").innerHTML = "长度必须在6-18位之间，只能包含字母，数字，下划线，";
//		return false;
//	}
//	if (pwd1.test(pwd)) {
//		document.getElementById("spoldpwd").innerHTML = "√";
//		
//	}
//	xmlhttp = new XMLHttpRequest();
//	
//	xmlhttp.onreadystatechange = resp1;
//	
//	var n = "ajaxpwd";
//	xmlhttp.open("get", ".../../QianLoginServlet?pwd=" + pwd + "&method=" + n,
//			true);
//
//	xmlhttp.send(null);
//	return true;
//}
//function resp1() {
//	
//	if (xmlhttp.readyState == 4) {
//		if (xmlhttp.status == 200) {
//			var txt = xmlhttp.responseText;
//			if (txt == 0) {
//				
//				document.getElementById("spoldpwd").innerHTML = "原密码不正确，请重新输入";
//			} else {
//				document.getElementById("spoldpwd").innerHTML = "√";
//
//			}
//		}
//	}
//
//}
//function cknewpwd() {
//	var newpwd = document.getElementById("newpwd").value;
//	var oldpwd = document.getElementById("oldpwd").value;
//	
//	if (newpwd == oldpwd) {
//		document.getElementById("spnewpwd").innerHTML = "新密码不能与原密码相同";
//		return false;
//	}
//	if (newpwd != oldpwd) {
//		document.getElementById("spnewpwd").innerHTML = "√";
//		
//	}
//	var pwd1 = /^[a-zA-Z]\w{5,17}$/;
//	
//	if (!pwd1.test(newpwd)) {
//		document.getElementById("spnewpwd").innerHTML = "长度必须在6-18位之间，只能包含字母，数字，下划线，";
//		return false;
//	}
//	if (pwd1.test(newpwd)) {
//		document.getElementById("spnewpwd").innerHTML = "√";
//		
//	}
//	return true;
//}
//function ckrepwd() {
//	var newpwd = document.getElementById("newpwd").value;
//	var repwd = document.getElementById("repwd").value;
//	var pwd1 = /^[a-zA-Z]\w{5,17}$/;
//	if (newpwd != repwd) {
//		document.getElementById("sprepwd").innerHTML = "两次密码必须一致";
//		return false;
//	}
//	if (newpwd == repwd) {
//		document.getElementById("sprepwd").innerHTML = "";
//		
//	}
//	if (!pwd1.test(repwd)) {
//		document.getElementById("sprepwd").innerHTML = "长度必须在6-18位之间，只能包含字母，数字，下划线，";
//		return false;
//	}
//	if (pwd1.test(repwd)) {
//		document.getElementById("sprepwd").innerHTML = "√";
//	}
//	return true;
//}
//function ckpwdall() {
//	var flag =  ckoldpwd() && cknewpwd() && ckrepwd();
//	if (flag == false) {
//		alert("请输入完整的内容");
//	}
//	return flag;
//}












